#include "ui_mouse.h"

uiMouse *uiMouse::createUiMouse(node *parent, const char *mouse_up_path, const char *mouse_down_path, float scale, Anchor anchor)
{
    auto ui_mouse = new uiMouse();
    ui_mouse->init();
    ui_mouse->mouse_up = sprite::createSprite(ui_mouse, mouse_up_path,scale, anchor);
    if(ui_mouse->mouse_up == nullptr) {
        SDL_Log("Failed to create mouse_up sprite");
    }
    ui_mouse->mouse_down = sprite::createSprite(ui_mouse, mouse_down_path,scale, anchor);
    if(ui_mouse->mouse_down == nullptr) {
        SDL_Log("Failed to create mouse_down sprite");
    }
    if(parent) parent->addChild(ui_mouse);
    return ui_mouse;
}

void uiMouse::update(float dt)
{
    if(!mouse_down || !mouse_up) return;
    timer_+= dt;
    if(timer_ < 0.3f){
        mouse_down->setActive(true);
        mouse_up->setActive(false);
    }else if(timer_ < 0.6f){
        mouse_down->setActive(false);
        mouse_up->setActive(true);
    }else{
        timer_ = 0.0f;
    }
    setRenderPosition(game_.getMousePosition());
}